﻿@using System.Xml.Linq

<ul class="archive">
@if(String.IsNullOrWhiteSpace(Model.Error))
{
    var xReport = Model.Data as XElement;
    var data = xReport != null && xReport.HasElements
        ? xReport.Elements("entry").Select(x => new
        {
            dt = DateTime.FromBinary(x.Attribute("dt").Value.ParseAs<Int64>()),
            count = x.Attribute("count").Value.ParseAs<Int32>()
        })
        : null;
    if(data != null && data.Any(x => x.count != 0))
    {
        foreach(var i in data.Where(x => x.count != 0).OrderByDescending(x => x.dt))
        {
            string month = T(Res.In("Common").Of("Date").Of("Month").Name(i.dt.Month));
            string label = T(Res.Name("Entry"), i.dt, month, i.count);
            string dtFrom = Svc.Date(i.dt);
            string dtTo = Svc.Date(i.dt.AddMonths(1));
            bool selected = Request.QueryParam("dtFrom").Equals(dtFrom) &&
                Request.QueryParam("dtTo").Equals(dtTo);
            <li><a class="@(selected ? "selected" : String.Empty)" href="@Url.Action(Loc.Act("Index").Set(new
            {
                id = Model.AuthorID,
                dtFrom,
                dtTo
            }).Localized())">@label</a></li>
        }
    }
    else
    {
        <li class="empty">@T(Res.In("Common").Of("Expr").Name("NoData"))</li>
    }
}
else
{
    <li class="error">@Model.Error</li>
}
</ul>
